import collections
class Solution(object):
    def toHexspeak(self, num):
        """
        :type num: str
        :rtype: str
        """
        num = int(num)
        d = {0: 'O', 1: 'I', 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
        s = collections.deque()
        while num >= 16:
            now_num = num % 16
            if now_num not in d:
                return 'ERROR'
            else:
                s.appendleft(d[now_num])
            num = num // 16
        if num not in d:
            return 'ERROR'
        else:
            s.appendleft(d[num])
        return ''.join(s)

data = Solution()
num = "3"
print(data.toHexspeak(num))
